package com.tqjc.system.core.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author 86195
 * @version 1.0
 * @description 文件工具类
 * @date 2023/9/21 14:21
 */
public class FileUtils {

    /**
     * 获取日期格式形式的文件路径
     * @return
     */
    public static String getFilePath(String pathPrefix){
        StringBuilder sb = new StringBuilder(pathPrefix);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateNow = dateFormat.format(new Date());
        String year = dateNow.substring(0, 4);
        String month = dateNow.substring(4, 6);
        String day = dateNow.substring(6);
        return sb.append("/").append(year).append("/").append(month).append("/").append(day).toString();
    }


    public static String getFilePath(String pathPrefix, LocalDateTime date){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String dateStr = date.format(formatter);
        StringBuilder sb = new StringBuilder(pathPrefix);
        String year = dateStr.substring(0, 4);
        String month = dateStr.substring(4, 6);
        String day = dateStr.substring(6);
        return sb.append("/").append(year).append("/").append(month).append("/").append(day).toString();
    }



}
